<?php
class HTMLSimpleDiary
{
	private $database;
	
	
	public function setDatabase($database)
	{
		$this->database = $database;
	}
	
	
	private function printYear($date)
	{
		return "<td class=\"EventReportYear\" colspan=\"4\">".$date->format("Y")."</td></tr><tr>";
	}
	
	private function printMonth($date)
	{
		return "<td class=\"EventReportMonth\" colspan=\"4\">".$date->format("F")."</td></tr><tr>";
	}
	
	private function printDay($date)
	{
		return "<td class=\"EventReportDay\" colspan=\"4\">".$date->format("j l")."</td></tr><tr>";
	}
	
	
	public function getHTML()
	{
		$dtNow = new DateTime("now");
		$valueNow = $dtNow->format("Y-m-d H:i");
		$sql = "SELECT * FROM Events WHERE Start > '".$valueNow."' AND DeletedBy = '0' ORDER BY Start";
		//echo $sql."\n";
		$this->database->ExecuteSQL($sql);
		$html = "";
		$html .= "<h2>Future events (excluding choir only)</h2>\n";
		
		$html .= "<table style=\"margin:auto;\">\n";
		
		$previousDate = new DateTime("-10 years");
		
		$users= new Enumeration($this->database,'SnapUsers');
		$array = $users->getArray();
		//print_r($array);
		
		while($row = $this->database->getRow())
		{
			
		// exclude choir only events
			$sql = "SELECT EventInvolveeNameID FROM EventInvolvees WHERE EventID = ".$row['EventID'];
			$database1 = $this->database->Recopy();
			$database1->ExecuteSQL($sql);
			$result = array();
			while($row1 = $database1->getRow())
			{
				$result[] = $row1['EventInvolveeNameID'];
			}
			
		//	echo $row['Title']."  -  ".count($result)."<br>\n";
			
			if(count($result)!=0) // if no involvees we need to include it
			{
				$dontskip = false;
				foreach($result as $involvee)
				{
					if(($involvee != 1)&&($involvee != 2)&&($involvee != 3)&&($involvee != 4)&&($involvee != 5))
					{
		//				echo "don't skip for involvee ".$involvee."<br>\n";
						$dontskip = true; // if not a choir involvee we need to include - otherwise skip
						break;
					}
				}
				if(!$dontskip)continue;
			}
			
			
			$start = new datetime($row['Start']);
			if($start->format("Y")!=$previousDate->format("Y"))$html .= $this->printYear($start);
			if($start->format("Ym")!=$previousDate->format("Ym"))$html .= $this->printMonth($start);
			if($start->format("Ymd")!=$previousDate->format("Ymd"))$html .= $this->printDay($start);
			$previousDate = $start;
			
			
			$startString = $start->format("H:i");
		//	$html .= "<tr><td width=\"20px\"></td><td".$style.">".$startString."</td><td".$style.">".$resultRow['EventID']."</td><td".$style.">".$resultRow['OriginalRecordID']."</td><td".$style.">".$resultRow['Title']."</td><td".$style.">".$resultRow['Description']."</td><td".$style.">".$text."&nbsp;".$strDate."</td></tr>\n";
			$html .= "<tr><td width=\"20px\"></td><td>".$startString."</td><td>".$row['Title']."</td><td>".$row['Description']."</td></tr>\n";
		}
		$html .= "</table>\n";
		
		return $html;
	}
}

?>

